package org.zizi.db.plan.reader;

import java.sql.ResultSet;

import org.zizi.convert.Converter;
import org.zizi.db.column.ColumnReader;
import org.zizi.db.plan.ResultReader;

public class PrimitiveResultReader<T> implements ResultReader<T>
{
	private Class<T> type;
	private ColumnReader reader;
	
	public PrimitiveResultReader(Class<T> type, ColumnReader reader)
	{
		this.reader = reader;
		this.type = type;
	}
	
	public T build(ResultSet rs) throws Exception
	{
		Object obj = reader.read(rs, 1);
		Object res = Converter.getConverter(type).convert(obj);
		
		return type.cast(res);
	}
}
